import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;


/*
 * export test data to server side
 */
public class ExportDataCsvUtil {
	/**
	 * test data will append to csv file 
	 */
	public void exportDataCsvWithAppend(String csvFilePath,String csvFileName,ArrayList<Double> dataCollected) {
		BufferedWriter bfWriter = null;
		try {
			bfWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(csvFilePath,csvFileName),true)));
			for(Double temData: dataCollected) {
				bfWriter.append(temData.toString()).append(",");
			}
			bfWriter.append("\r\n");
			bfWriter.flush();
		}catch(Exception e) {
			e.printStackTrace();
		}finally{
			if(bfWriter != null) {
				
					try {
						bfWriter.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
			}
		}
		
		
	}
	
	
	public static void main(String [] args) {
		ArrayList<Double> dataCollected = new ArrayList<Double>();
		dataCollected.add(1.0);
		dataCollected.add(4.0);
		new ExportDataCsvUtil().exportDataCsvWithAppend("D://","test.csv",dataCollected);
		System.out.println("add success");
	}
}
